<?php
App::uses('AppController', 'Controller');
/**
 * Studentinfos Controller
 *
 * @property Studentinfo $Studentinfo
 */
class StudentinfosController extends AppController {


/**
 * index method
 *
 * @return void
 */
	public function index() {
		$this->Studentinfo->recursive = 0;
		$this->set('studentinfos', $this->paginate());
	}

/**
 * view method
 *
 * @param string $id
 * @return void
 */
	public function view($id = null) {
		$this->Studentinfo->id = $id;
		if (!$this->Studentinfo->exists()) {
			throw new NotFoundException(__('Invalid studentinfo'));
		}
		$this->set('studentinfo', $this->Studentinfo->read(null, $id));
	}

/**
 * add method
 *
 * @return void
 */
	public function add() {
		if ($this->request->is('post')) {
			$this->Studentinfo->create();
			if ($this->Studentinfo->save($this->request->data)) {
				$this->Session->setFlash(__('The studentinfo has been saved'));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The studentinfo could not be saved. Please, try again.'));
			}
		}
		$students = $this->Studentinfo->Student->find('list');
		$genders = $this->Studentinfo->Gender->find('list');
		$citizenships = $this->Studentinfo->Citizenship->find('list');
		$foreignlanguages = $this->Studentinfo->Foreignlanguage->find('list');
		$educationlines = $this->Studentinfo->Educationline->find('list');
		$hostels = $this->Studentinfo->Hostel->find('list');
		$this->set(compact('students', 'genders', 'citizenships', 'foreignlanguages', 'educationlines', 'hostels'));
	}

/**
 * edit method
 *
 * @param string $id
 * @return void
 */
	public function edit($id = null) {
		$this->Studentinfo->id = $id;
		if (!$this->Studentinfo->exists()) {
			throw new NotFoundException(__('Invalid studentinfo'));
		}
		if ($this->request->is('post') || $this->request->is('put')) {
			if ($this->Studentinfo->save($this->request->data)) {
				$this->Session->setFlash(__('The studentinfo has been saved'));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The studentinfo could not be saved. Please, try again.'));
			}
		} else {
			$this->request->data = $this->Studentinfo->read(null, $id);
		}
		$students = $this->Studentinfo->Student->find('list');
		$genders = $this->Studentinfo->Gender->find('list');
		$citizenships = $this->Studentinfo->Citizenship->find('list');
		$foreignlanguages = $this->Studentinfo->Foreignlanguage->find('list');
		$educationlines = $this->Studentinfo->Educationline->find('list');
		$hostels = $this->Studentinfo->Hostel->find('list');
		$this->set(compact('students', 'genders', 'citizenships', 'foreignlanguages', 'educationlines', 'hostels'));
	}

/**
 * delete method
 *
 * @param string $id
 * @return void
 */
	public function delete($id = null) {
		if (!$this->request->is('post')) {
			throw new MethodNotAllowedException();
		}
		$this->Studentinfo->id = $id;
		if (!$this->Studentinfo->exists()) {
			throw new NotFoundException(__('Invalid studentinfo'));
		}
		if ($this->Studentinfo->delete()) {
			$this->Session->setFlash(__('Studentinfo deleted'));
			$this->redirect(array('action' => 'index'));
		}
		$this->Session->setFlash(__('Studentinfo was not deleted'));
		$this->redirect(array('action' => 'index'));
	}
	public function showinfo($id) {
		$student = $this->Studentinfo->find('all', array('conditions' => array('Studentinfo.student_id' => $id)));
		$this->set(compact('student'));
		$this->loadModel('Visastype');
		if (isset($student[0]['Visa'][0]['visastype_id'])) {
		  $visastype = $this->Visastype->find('all', array('conditions' => array('Visastype.id' => $student[0]['Visa'][0]['visastype_id']),'recursive' => -1));
		  $this->set(compact('visastype'));
		}
		$this->loadModel('Insurance');
		if (isset($student[0]['Studentinsurance'][0]['insurance_id'])) {
		  $insurance = $this->Insurance->find('all', array('conditions' => array('Insurance.id' => $student[0]['Studentinsurance'][0]['insurance_id']),'recursive' => -1));
		  $this->set(compact('insurance'));
		}
		$this->loadModel('Order');
		$order = $this->Order->find('all', array('conditions' => array('Order.student_id' => $student[0]['Student']['id']),'recursive' => 1));
		$this->set(compact('order'));
	}
}
